<template>
	<view>
		<view class="title"></view>
		<view class="main">
			<u-form :model="form" label-width="160">
				<u-form-item label="用户名">
					<u-input v-model="form.username"></u-input>
				</u-form-item>
				<u-form-item label="密码">
					<u-input type="password" v-model="form.password"></u-input>
				</u-form-item>
			</u-form>
			<navigator url="/pages/register/register" class="register">没有账号？点击这里注册</navigator>
		</view>
		<button class="bu" style="margin-top: 50rpx;" @click="submit">登录</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					username: '',
					password: ''
				}
			};
		},
		methods:{
			submit(){
				this.$request({
					url: '/prod-api/api/login',
					method: 'POST',
					data: {
						...this.form
					}
				}).then(res => {
					if(res.code === 200){
						uni.showToast({
							title:'登陆成功'
						})
						uni.setStorageSync('token',res.token)
						setTimeout(() => {
							uni.reLaunch({
								url:'/pages/index/index'
							})
						}, 1000)
					}else{
						uni.showToast({
							icon:'error',
							title: res.msg
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
view{
	padding: 20rpx;
	.title{
		color: #2979ff;
		font-size: 45rpx;
		font-weight: bold;
		text-align: center;
	}
	.main{
		padding: 20rpx;
		position: relative;
		.register{
			width: fit-content;
			position: absolute;
			right: 0;
			bottom: 0;
			color: #2979ff;
			font-size: 26rpx;
		}
	}
}
</style>
